package com.app;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.db.DBCreator;

public class Application {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Connection con = DBCreator.getConnection();
		try {
			Statement s = con.createStatement();
			System.out.println("sql = "+DBCreator.createTradeTableString);
			s.execute(DBCreator.createTradeTableString);
			PreparedStatement psInsert = con
					.prepareStatement("insert into WISH_LIST(WISH_ITEM) values (?)");
			psInsert.setString(1, "i got it");
			psInsert.executeUpdate();
			ResultSet myWishes = s
					.executeQuery("select ENTRY_DATE, WISH_ITEM from WISH_LIST order by ENTRY_DATE");
			while (myWishes.next()) {
				System.out.println("On " + myWishes.getTimestamp(1)
						+ " I wished for " + myWishes.getString(2));
			}
			myWishes.close();
			psInsert.close();
			s.close();
			con.close();
		} catch (SQLException e1) {
			e1.printStackTrace();
		}
		//Shutdown database
		try {
			DriverManager.getConnection("jdbc:derby:;shutdown=true");
		} catch (SQLException e) {			
			if ( !e.getSQLState().equals("XJ015") ) {	
				System.out.println("Database did not shut down normally");
				e.printStackTrace();
			}
			
		}
		System.out.println(System.getProperty("user.dir"));
	}

}
